<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 定义一个含有30个整型元素的数组，按顺序分别赋予从2开始的偶数；然后按顺序每五个数求出一个平均值，放在另一个数组中并输出
        // 1、创建数组30个元素
        var data = [];
        for (var i = 1; i <= 30; i++) {
            data[i - 1] = i * 2;
        }

        var sum = 0; //保存和
        var avg = [];
        for (var j = 0; j < data.length; j++) {
            sum += data[j];
            // (j+1)%5 ==0 每5个数
            if ((j + 1) % 5 == 0) {
                avg[avg.length] = sum / 5
                // 重置sum
                sum = 0;
            }
        }
        console.log(avg);
    </script>
</body>

</html>